package com.crawler.harbour.utils;

public class CookieUtil {

	
	/**
	 * 从cookie字符串获取指定名称的值
	 * @param keyName 要获取的名称
	 * @param cookieStr cookie字段
	 * @return keyName对应的value 或者null
	 */
	public static String getValueByCookieName(String keyName,String cookieStr) {
		String[] cookies= cookieStr.split(";");
		String value=null;
		for (int i = 0; i < cookies.length; i++) {
			if(cookies[i].contains(keyName+"=")) {
				int index= cookies[i].indexOf("=")+1;
				value= cookies[i].substring(index);
			}
		}
		return value;
	}
}

